package qr.core;

import java.util.ArrayList;
import java.util.List;

import org.simpleframework.xml.ElementList;
import org.simpleframework.xml.Root;
import org.simpleframework.xml.Transient;

@Root
public class Game {
	
	private long id;
	
	@ElementList
	private ArrayList<Location> locations;
	
	@Transient
	private Leaderboard leaderboard; 
	private long startTime;
	private int gameDuration; 
	private String gameName;
	private boolean isStarted; 
	
	public Game() {
		gameName = "New Game";
		gameDuration = 60;
		locations = new ArrayList<Location>();
		leaderboard = new Leaderboard(); 
	}
	
	/**
	 * Method to set the duration of game
	 * @return - duration of game
	 */
	public void setGameDuration(int duration) { 
		
		gameDuration = duration; 
	}
	
	public int getGameDuration() { 
		
		return gameDuration; 
	}
	
	public void addLocation(Location location) { 
		
		locations.add(location);
	}
	
	public void removeLocation(Location location) {
		
		locations.remove(location);
	}
	
	public ArrayList<Location> getLocations() {
		return locations;
	}

	public void setLocations(ArrayList<Location> locations) {
		this.locations = locations;
	}

	public long getStartTime() {
		return startTime;
	}

	public void setStartTime(long startTime) {
		this.startTime = startTime;
	}
	
	public String getGameName() {
		return gameName;
	}
	
	public void setGameName(String name) { 
		
		this.gameName = name;
	}
	
	public void setLeaderboard(Leaderboard board){
		
		this.leaderboard = board;
	}
	
	public Leaderboard getLeaderboard() { 
		
		return leaderboard; 
	}
	
	public boolean isRunning() { 
		
		return isStarted; 
	}
	
	public boolean getIsStarted() { 
		return isStarted; 
	}
	
	public void setIsStarted(boolean started) { 
		isStarted = started; 
	}
	
	public void startGame() {
		isStarted = true;
		startTime = System.currentTimeMillis();
	}
	
	public void stopGame() {
		isStarted = false;
		startTime = 0;
	}

	public String toString() {
		return gameName;
	}

	public long getId() {
		// TODO Auto-generated method stub
		return this.id;
	}

	public List<Player> getPlayers() {
		// TODO Auto-generated method stub
		return getLeaderboard().getPlayers();
	}
	
}